from no.uib.cipr.matrix import *
from java.lang import *
from java.util.concurrent import *

SIZE = 100
TASKS = 10
barrier = CyclicBarrier(TASKS + 1)

class EigenTask(Runnable):
    def __init__(self, n, barrier):
        self.n = n
        self.barrier = barrier
    def run(self):
        matrix = Matrices.random(self.n, self.n)
        evd = EVD.factorize(matrix)
        self.realEigs = evd.getRealEigenvalues()
        self.imagEigs = evd.getImaginaryEigenvalues()
        self.matrix = matrix
        self.barrier.await()

pool = Executors.newCachedThreadPool()

tasks = []
futures = []
for i in range(TASKS):
    task = EigenTask(SIZE, barrier)
    tasks.append(task)
    future = pool.submit(task)
    futures.append(future)

barrier.await()

print 'Eigenvalue computation tasks completed'
